package com.ruoyi.ebike.service.impl;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ebike.utils.PointUtils;
import com.ruoyi.ebike.vo.DeptVO;
import com.ruoyi.ebike.domain.Vehicle;
import com.ruoyi.ebike.mapper.DeployMapper;
import com.ruoyi.ebike.service.IDeployService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Collections;

@Service
public class DeployServiceImpl implements IDeployService {

    @Autowired
    private DeployMapper deployMapper;
//    public int addSingleVehicle(Vehicle vehicle){
//        return deployMapper.addSingleVehicle();
//    }

    @Override
    public List<SysDept> fetchDeptlist() {
        LoginUser loginUser = SecurityUtils.getLoginUser();     //获取当前登录的用户信息
        SysUser currentUser = loginUser.getUser();
        Long deptId = currentUser.getDeptId();
        return deployMapper.fetchDeptlist(deptId);
    }

    @Override
    public int addSingleVehicle(Vehicle vehicle) {
        vehicle.setPoint(PointUtils.getRandomPoint());

        return deployMapper.addSingleVehicle(vehicle);
    }

    @Override
    @Transactional
    public int addBatchVehicles(List<Vehicle> vehicles) {
        for (Vehicle vehicle : vehicles) {
            vehicle.setPoint(PointUtils.getRandomPoint());
        }
        return deployMapper.addBatchVehicles(vehicles);

    }

    @Override
    @Transactional
    public int updateDeployStatus(List<Vehicle> vehicles) {
        return deployMapper.updateDeployStatus(vehicles);
    }
    @Override
    @Transactional
    public int updateBatchVehicles(List<Vehicle> vehicles) {
        return deployMapper.updateBatchVehicles(vehicles);
    }


}
